<template>
    <div>
        <table>
            <tr>
                <td>编号</td>
                <td>姓名</td>
                <td>等级</td>
                <td>操作</td>
            </tr>
            <tr v-for="u in user_list" :key="u.id">
                <td>{{u.id}}</td>
                <td>{{u.user_name}}</td>
                <td>{{u.leave.name}}</td>
                <td>
                    <button @click="upleave(u.id,u.leave.id)">升级</button>
                </td>
            </tr>
        </table>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    name:'Showuser',
    data() {
        return {
            
            user_list:[]
        }
    },
    methods: {
        get_user(){
            axios({
                url:'http://127.0.0.1:8000/app01/user_api',
                
            }).then(res=>{
                console.log(res.data)
                this.user_list = res.data.data
            })
        },
        upleave(uid,lid){
            let formdata = new FormData()
            formdata.append('user_id',this.uid)
            formdata.append('leave_id',this.lid)

            axios({
                urL:'http://127.0.0.1:8000/app01/user_api',
                method:'post',
                data:formdata
            }).then(res=>{
                console.log(res.data)
                this.get_user()
            })
        }
    },
    created() {
        this.get_user()
    }
}
</script>

<style>

</style>
